// 封装一个存储模块，用于操作本地存储
const tokenKey = 'yoyo-mobile'
const historyKey = 'search-history'

/**
 * 设置token
 * @param tokenObj token
 */
export const setToken = (tokenObj) => {
  localStorage.setItem(tokenKey, JSON.stringify(tokenObj))
}

/**
 * 获取token
 */
export const getToken = () => {
  return JSON.parse(localStorage.getItem(tokenKey)) || {}
}

/**
 * 刷新token
 */
export const removeToken = () => {
  localStorage.removeItem(tokenKey)
}

/**
 * 存历史搜索记录
 * @param historyInfo
 */
export const setHistory = (historyInfo) => {
  localStorage.setItem(historyKey, JSON.stringify(historyInfo))
}

/**
 * 取历史搜索记录
 * @returns {any|*[]}
 */
export const getHistory = () => {
  // 取数据需要return返回
  return JSON.parse(localStorage.getItem(historyKey)) || []
}

/**
 * 移除历史搜索记录
 */
export const removeHistory = () => {
  localStorage.removeItem(historyKey)
}
